# 写一个竞猜游戏，用户必须猜一个秘密的数字，在每次猜完后程序会告诉用户他猜的数是太大了还是太小了，直到猜测正确，
# 最后打印出猜测的次数。如果用户连续猜测同一个数字则只算一次。
import random

count=0
last = 0
# todo:last=0？也可以
number = random.randint(1, 101)
#random后面有个点
guess=-1
a = 1
b = 100
while guess!=number:
    guess = int(input("请猜一个%d-%d范围内的整数：" % (a, b)))
    #这里如果用print就没办法改变guess的值了，实际上guess是每次输入不一样的,所以guess要在while里面
    if guess!=last:
        count=count+1
    last=guess
    if guess < number:
        a = guess
        print("您猜的数小了")
    if guess > number:
        b = guess
        print("您猜的数大了")
    if guess == number:
        print("您猜对了 总共用了%d次" % count)
#
        # count=0
        # last=0
        # a=1
        # b=100
        # guess=-1
# import random
        # number=random. randint(1,101)
        # while guess!=number
        #     guess = int(input("请猜一个%d-%d的整数：" % (a, b)))
        #     guess!=last
        #     count=count+1
        #     last=guess
        #     if guess<number
        #         a=guess
#         print("您猜的数小了")
        #     if guess>number
        #         b=guess
#         print("您猜的数大了")
        #     if guess==number
        #         print("您猜对了，总共猜了%d次"%count)
